package com.jvyou.framework.controller;



import com.jvyou.framework.domain.dto.MenuDto;
import com.jvyou.framework.domain.entity.Menu;
import com.jvyou.framework.service.MenuService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import java.util.List;
import com.jvyou.common.annotation.Log;
import com.jvyou.common.core.domain.model.PageResult;
import com.jvyou.common.core.domain.model.Result;
import com.jvyou.common.enums.log.BusinessType;
import com.jvyou.common.enums.result.HttpCodeEnum;


/**
 * 菜单权限表(Menu)表控制层
 *
 * @author 橘柚
 * @since 2025-05-29 17:25:16
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/menu")
public class MenuController  {
    
    private final MenuService menuService;
    
     /**
     * 查询菜单权限表列表
     *
     * @param dto 查询参数
     * @return 菜单权限表
     */
    @GetMapping("/list")
    @SaCheckPermission("sys:menu:list")
    @Log(title = "查询菜单权限表列表", businessType = BusinessType.OTHER)
    public Result<List<Menu>> list(@ModelAttribute MenuDto dto) {
        return Result.success(menuService.listMenu(dto));
    }

     /**
     * 分页查询菜单权限表列表
     *
     * @param dto 查询参数
     * @return 菜单权限表
     */
    @GetMapping("/page")
    @SaCheckPermission("sys:menu:page")
    @Log(title = "分页查询菜单权限表列表", businessType = BusinessType.OTHER)
    public Result<PageResult<Menu>> page(@ModelAttribute MenuDto dto) {
        return Result.success(menuService.pageMenu(dto));
    }

    /**
     * 通过主键查询菜单权限表单条
     *
     * @param id 菜单权限表主键
     * @return 菜单权限表
     */
    @GetMapping("/{id}")
    @Log(title = "通过主键查询菜单权限表")
    @SaCheckPermission("sys:menu:get")
    public Result<Menu> selectOne(@PathVariable Long id) {
        return Result.success(menuService.getById(id));
    }

    /**
     * 新增菜单权限表
     *
     * @param menu 菜单权限表实体对象
     * @return 新增菜单权限表结果
     */
    @PostMapping
    @Log(title = "新增菜单权限表",  businessType = BusinessType.INSERT)
    @SaCheckPermission("sys:menu:insert")
    public Result<Menu> insert(@RequestBody Menu menu) {
        boolean success = menuService.save(menu);
        return success ? Result.success(menu) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
     /**
     * 修改菜单权限表
     *
     * @param menu 菜单权限表实体对象
     * @return 修改菜单权限表结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("sys:menu:update")
    @Log(title = "修改菜单权限表数据", businessType = BusinessType.UPDATE)
    public Result<Menu> updateById(@RequestBody Menu menu) {
        boolean success = menuService.updateById(menu);
        return success ? Result.success(menu) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除菜单权限表数据
     *
     * @param id 菜单权限表主键
     * @return 删除菜单权限表结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("sys:menu:delete")
    @Log(title = "删除菜单权限表",  businessType = BusinessType.DELETE)
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = menuService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
    
}

